<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\UserAuthStepEventLog
 *
 * @property int $id
 * @property int $uid 用户ID
 * @property int $step_id 各步骤ID
 * @property int $type 步骤类型
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserAuthStepEventLog newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserAuthStepEventLog newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserAuthStepEventLog query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserAuthStepEventLog whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserAuthStepEventLog whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserAuthStepEventLog whereStepId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserAuthStepEventLog whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserAuthStepEventLog whereUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserAuthStepEventLog whereUpdatedAt($value)
 * @mixin \Eloquent
 * @property int $loan_request_id 借款请求ID@user_loan_request.id
 * @property-read mixed $step
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserAuthStepEventLog byLoanId($loanId)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserAuthStepEventLog byUserId($user_id)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserAuthStepEventLog whereLoanRequestId($value)
 * @property int $is_current 是否是当前步骤 1=当前 2=非当前
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserAuthStepEventLog whereIsCurrent($value)
 */
class UserAuthStepEventLog extends Model {
    /**
     * 身份证实名
     */
    CONST STEP_OCR           = 1;
    /**
     * 人脸识别
     */
    CONST STEP_FACE          = 2;
    /**
     * 基础信息
     */
    CONST STEP_INFO          = 3;
    /**
     * 选择银行卡
     */
    CONST STEP_BIND_CASH     = 4;
    /**
     * 选择信用卡
     */
    CONST STEP_BIND_CREDIT   = 5;
    /**
     * 手机运营商
     */
    CONST STEP_PHONE_SERVICE = 6;
    /**
     * 芝麻信用
     */
    CONST STEP_ZHIMA         = 7;

    /*
     * 当前步骤 1=是 2=否
     * */
    const CURRENT_STEP_YES = 1,CURRENT_STEP_NO = 2;

    static $STEPS = [
        self::STEP_OCR           => '实名认证',
        self::STEP_FACE          => '人脸识别',
        self::STEP_INFO          => '个人信息',
        self::STEP_BIND_CASH     => '储蓄卡',
        self::STEP_BIND_CREDIT   => '信用卡',
        self::STEP_PHONE_SERVICE => '通话详单',
        self::STEP_ZHIMA         => '芝麻信用',
    ];
    protected $fillable = ['uid', 'step_id', 'type','loan_request_id','is_current'];

    public function getStepAttribute(){
        $keys = array_keys(self::$STEPS);
        if($this->attributes['type'] && in_array($this->attributes['type'], $keys)){
            return self::$STEPS[$this->attributes['type']];
        }
        return 'error';
    }

    public function scopeByLoanId($q,$loanId){
        return $q->where('loan_request_id',$loanId);
    }

    /**
     * Description:用户id作用域
     * Author: Sam
     * DateTime: 2019/1/8 14:53
     * @param $query
     * @param $user_id
     * @return mixed
     */
    public function scopeByUserId($query,$user_id)
    {
        return $query->where('uid',$user_id);
    }
}
